

import wsgiref.handlers

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from BeautifulSoup import BeautifulSoup
from xmw.tianya.bot import *

from xmw import tianya

from xmw import error
import os
import urllib2, urllib
import uuid

from google.appengine.ext import webapp

class MainPage(xmw.RequestHandler):
    def get(self):
        if  not self.request.GET.has_key('thread_id'):
            e = error.ARGUMENT_FAULT("URI:query_thread needs parameter thread_id.    /portal/query_thread?url=XXXX")
            self.render_error(e)
            return
        
        thread_id = self.request.GET['thread_id']
        
        thread_q=Bot_Thread.all()
        thread_q.filter('thread_id =',thread_id)
        thread=thread_q.get()
        
        if thread is None:
            e   =error.THREAD_NOT_EXIST("thread_id:%s"%thread_id)
            self.render_error(e)
            return
        
        template_values = {
                               "thread":thread
                        }
        self.render_template(template_values, 'thread')
        return 
        

def main():
    application = webapp.WSGIApplication(
                                       [('/portal/query_thread', MainPage)],
                                       debug=True)
    wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()
